/**
* saleonwhatsapp
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @author FME Modules
* @copyright 2021 FMM Modules All right reserved
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* @category FMM Modules
* @package saleonwhatsapp
*/
$(function () {
//jQuery time
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches
$(".next").click(function () {
if (animating) return false;
animating = true;
current_fs = $(this).parent();
next_fs = $(this).parent().next();
//activate next step on progressbar using the index of next_fs
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate(
{ opacity: 0 },
{
step: function (now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = now * 50 + "%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({ transform: "scale(" + scale + ")" });
next_fs.css({ left: left, opacity: opacity });
},
duration: 800,
complete: function () {
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: "easeInOutBack",
}
);
});
$(".previous").click(function () {
if (animating) return false;
animating = true;
current_fs = $(this).parent();
previous_fs = $(this).parent().prev();
//de-activate current step on progressbar
$("#progressbar li")
.eq($("fieldset").index(current_fs))
.removeClass("active");
//show the previous fieldset
previous_fs.show();
//hide the current fieldset with style
current_fs.animate(
{ opacity: 0 },
{
step: function (now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale previous_fs from 80% to 100%
scale = 0.8 + (1 - now) * 0.2;
//2. take current_fs to the right(50%) - from 0%
left = (1 - now) * 50 + "%";
//3. increase opacity of previous_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({ left: left });
previous_fs.css({
transform: "scale(" + scale + ")",
opacity: opacity,
});
},
duration: 800,
complete: function () {
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: "easeInOutBack",
}
);
});
$(".submit").click(function () {
return false;
});
});
$(document).on("click", "#to-order-step", function (event) {
$(".cus-firstname").html($("#first_name").val());
$(".cus-lastname").html($("#last_name").val());
$(".cus-phone").html($("#phone").val());
$(".cus-email").html($("#email").val());
$(".cus-address").html($("#address").val());
$(".cus-city").html($("#city").val());
$(".cus-country").html($("#id_country option:selected").text());
$(".cus-state").html($("#id_sow_state option:selected").text());
});
$(document).on("click", "#sow-16", function (event) {
var id_product = $("#sow_id_product").val();
event.preventDefault();
$.fancybox.open({
width: 900,
// 'height': 400,
autoSize: false,
beforeLoad: function () {
// if (site_key != '' && site_key)
// $('#submit_cont').hide();
},
closeClick: false, // prevents closing when clicking INSIDE fancybox
href: sow_modal,
type: "ajax",
openEffect: "none",
closeEffect: "none",
helpers: {
overlay: { closeClick: false }, // prevents closing when clicking OUTSIDE fancybox
},
ajax: {
type: "POST",
dataType: "json",
url: sow_modal,
data: {
ajax: true,
id_prod: id_product,
curr_cont: sow_curr_cont,
},
success: function (response) {
$("div#fmm-sow-error").hide();
if (response.error == true) {
$("div#fmm-sow-error").text(response.message).show();
} else {
$("#id_sow_state").empty();
if (response.fmm_sow_states.length > 0) {
response.fmm_sow_states.forEach(loadFmmState);
}
}
},
},
});
});
$(function () {
$("#sow_chat").floatingWhatsApp({
phone: chat_phone,
popupMessage: chat_popup,
message: chat_message,
showPopup: true,
showOnIE: false,
headerTitle: "Welcome!",
headerColor: chat_header_color,
backgroundColor: chat_background_color,
buttonImage: "
",
});
});
$(document).ready(function () {
$("div#fmm-sow-error").hide();
});
$(document).on("change", "#id_country", function () {
var id_country = $(this).val();
id_country = parseInt(id_country);
if (id_country) {
$("div#fmm-sow-error").hide();
$.ajax({
type: "post",
url: sow_load_state,
data: {
id_country: id_country,
},
dataType: "json",
success: function (response) {
if (response.error == true) {
$("div#fmm-sow-error").text(response.message).show();
} else {
$("#id_sow_state").empty();
if (response.fmm_sow_states.length > 0) {
response.fmm_sow_states.forEach(loadFmmState);
}
}
},
error: function (xhr, status, error) {
console.log(
status_code_l +
": " +
xhr.status +
". " +
error_l +
": " +
error +
". " +
response_text_l +
": " +
xhr.responseText +
"."
);
},
});
} else {
$("div#fmm-sow-error").show();
}
});
function loadFmmState(state) {
$("#id_sow_state").append(
'"
);
}
$(document).on("click", "#sow_order", function () {
if (sow_curr_cont == "product") {
var first_name = $("#first_name").val();
var last_name = $("#last_name").val();
var phone = $("#phone").val();
var email = $("#email").val();
var id_country = $("#id_country").val();
id_country = parseInt(id_country);
var id_sow_state = $("#id_sow_state").val();
var address = $("#address").val();
var city = $("#city").val();
var sow_qty_wanted = $("#quantity_wanted").val();
// Version variable if 1 means version is above 1.7.0.0
if (sow_v) {
var fmm_sow_json = $("#product-details").attr("data-product");
var fmm_sow_json = JSON.parse(fmm_sow_json);
var id_product = fmm_sow_json["id"];
var id_comb = fmm_sow_json["id_product_attribute"];
} else {
var id_product = $("#sow_id_product").val();
var id_comb = $("#idCombination").val();
}
$("div#fmm-sow-error").hide();
$.ajax({
type: "post",
url: sow_order,
data: {
first_name: first_name,
last_name: last_name,
phone: phone,
email: email,
id_sow_state: id_sow_state,
address: address,
id_country: id_country,
city: city,
sow_curr_cont: sow_curr_cont,
id_prod: id_product,
id_comb: id_comb,
sow_qty_wanted: sow_qty_wanted,
},
dataType: "json",
success: function (response) {
if (response.error == true) {
$("div#fmm-sow-error").text(response.message).show();
$("div#fmm-sow-error").show();
} else {
location.href = response.data.order_link;
}
},
error: function (xhr, status, error) {
console.log(
status_code_l +
": " +
xhr.status +
". " +
error_l +
": " +
error +
". " +
response_text_l +
": " +
xhr.responseText +
"."
);
},
});
// } else {
// $("div#fmm-sow-error").show();
// }
} else {
var first_name = $("#first_name").val();
var last_name = $("#last_name").val();
var phone = $("#phone").val();
var email = $("#email").val();
var id_country = $("#id_country").val();
id_country = parseInt(id_country);
var id_sow_state = $("#id_sow_state").val();
var address = $("#address").val();
var city = $("#city").val();
$("div#fmm-sow-error").hide();
$.ajax({
type: "post",
url: sow_order,
data: {
first_name: first_name,
last_name: last_name,
phone: phone,
email: email,
id_sow_state: id_sow_state,
address: address,
id_country: id_country,
city: city,
sow_curr_cont: sow_curr_cont,
},
dataType: "json",
success: function (response) {
if (response.error == true) {
$("div#fmm-sow-error").text(response.message).show();
$("div#fmm-sow-error").show();
} else {
console.log(response.data.order_link);
location.href = response.data.order_link;
}
},
error: function (xhr, status, error) {
console.log(
status_code_l +
": " +
xhr.status +
". " +
error_l +
": " +
error +
". " +
response_text_l +
": " +
xhr.responseText +
"."
);
},
});
}
});